<template>
	<view>
		<swiper
			style="width: 100vw; height: 100vh"
			:indicator-dots="true"
			:autoplay="false"
			:duration="500">
			<swiper-item
				v-for="(item, index) in dataList"
				:key="index">
				<view style="position: relative;height: 100vh">
					<x-image :src="showImage(item.imgUrl, 'logo')" mode="aspectFill"/>
					<view
					v-if="index === dataList.length - 1"
					class="btn bg-primary"
					@click="jumpLogin"
					>{{ lang_once.use }}</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { GUIDE_NAME, BASE_URL } from '@/config.js'
	import { Banner } from '@/api/base.js' 
	export default {
		data() {
			return {
				dataList: []
			}
		},
		created() {
			this.initGuide()
		},
		methods: {
			// 跳转到登录页
			jumpLogin() {
				uni.setStorageSync(GUIDE_NAME, 'ok')
				let { otherLink, otherLinkUrls } = this.$store.state.common || {}
				let otherLinkQuery = (otherLink || '').split('&')
				let typeIndex = otherLinkQuery.findIndex(item => item.indexOf('type=') > -1)
				console.log(otherLink)
				if (typeIndex > -1) {
					let typeStr = otherLinkQuery[typeIndex]
					let page = (otherLinkUrls || {})[typeStr.split('=')[1]]
					console.log(page)
					this.$store.commit('INIT_OTHER_LINK', '')
					if (page) {
						uni.reLaunch({
							url: page + `?${ otherLinkQuery.filter(item => item !== typeStr).join('&') }`
						})
						return 
					}
				}
				uni.reLaunch({
					url: '/pages/first/select/select'
				})
			},
			// 初始化引导页
			initGuide() {
				Banner({ type: 3 }).then((result) => {
					this.dataList = result
				})
				.finally(() => {
					if (!this.dataList.length) {
						this.jumpLogin()
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.btn {
		position: absolute;
		left: 50%;
		bottom: 160rpx;
		transform: translateX(-50%);
		padding: 20rpx 40rpx;
		color: #ffffff;
		background-color: #FF3A2F;
		border-radius: 10rpx;
	}
</style>
